<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<script type="text/javascript">
	$(function(){
		window.m_datagrid = $('#m_datagrid').datagrid({
			url:'${ctx}/xf/premises/outsidePremisesList',
			onLoadSuccess:yixun.closeProgress,
			onBeforeLoad:yixun.progress,
			queryParams:$('#load_list_search').serializeObject(),
			loadMsg:null,
			singleSelect:true,
			fitColumns:false,
			rownumbers:true,
			pagination:true,
			border:'false',
			toolbar:'#m_toolbar'
		});
	
		//按条件查询用户
		window.searchData = function () {
			m_datagrid.datagrid('load',$('#load_list_search').serializeObject());
		}
		
		//删除
		window.deleteDate = function(mid){
			$.messager.confirm('确认!','你确定要删除此数据吗?',function(res){
				if(res){
					$.post("${ctx}/xf/premises/del",{'id':mid},function(result){
						if (result.errorMsg){
							$.messager.show({
								title: '友情提示',
								msg: 'result.errorMsg'
							});
							m_datagrid.datagrid('reload');
						} else {
							$.messager.show({
								title: '友情提示',
								msg: '删除成功'
							});
						}
					},'json');
				}
			});
		}
	});
	
	mShowButton = function (value,row,index){
		var btns = [];
        if(row.marketingNumber){
            btns.push('<button class="green_btn" onclick="javascript:bindAccount('+value+','+"0"+',\'解绑\');void(0);">解绑</button>');
        }else{
            btns.push('<button class="green_btn" onclick="javascript:bindAccount('+value+','+"1"+',\'绑定\');void(0);">绑定</button>');
        }
		btns.push('<button class="green_btn" onclick="javascript:window.location.href=\'outsidePremisesCheck?id='+value+'\';void(0);">查看</button>');
            if(row.shelvesStatus == 1){
            btns.push('<button class="green_btn" onclick="javascript:changeShelvesStatus('+value+','+row.shelvesStatus+',\'下架\');void(0);">下架</button>');
		}else{
            btns.push('<button class="green_btn" onclick="javascript:changeShelvesStatus('+value+','+row.shelvesStatus+',\'上架\');void(0);">上架</button>');
        }
		return btns.join('');
	}
	
    formatShelvesStatus = function (value,row,index){
		if(value=="0"){
		  return "下架";
		}else if(value=="1"){
		  return "上架";
		}
		return "";
	}
	
	changeShelvesStatus = function (id,status,title) {
	    if(!status){
	        status = 0;
		}
		var param = {
            'id':id,
			'shelvesStatus': status
		}
        $.messager.confirm('确认!','你确定要'+title+'吗?',function(res){
            if(res){
                $.post("${ctx}/xf/premises/changeShelvesStatus",param,function(response){
                    if (response.result == "1"){
                        $.messager.show({
                            title: '友情提示',
                            msg:'操作成功',
                            timeout:2000,
                            showType:'show',
                            style:{
								left:'',
								right:0,
								top:window.screen.height*0.8,
								bottom:''
							}
                        });
                        m_datagrid.datagrid('reload');
                    } else {
                        $.messager.show({
                            title: '友情提示',
                            msg: '操作失败',
                            timeout:2000,
                            showType:'show',
                            style:{
								left:'',
								right:0,
								top:window.screen.height*0.8,
								bottom:''
							}
                        });
                    }
                },'json');
            }
        });

		$("#page-body").find(".window-shadow").css({"display": "block",
			"width": "300px",
			"left": "40%",
			"top": "10%",
			"z-index": "9035",
			"position": "absolute"});
		$("#page-body").find(".messager-window").css({"display": "block",
			"width": "300px",
			"left": "40%",
			"top": "10%",
			"z-index": "9036",
			"position": "absolute"});
		$("#indexPage",parent.document).animate({"scrollTop": "150px"}, 100);
    }
    
	bindAccount = function (id,status,title) {
        var param = {
            'id':id,
            'bindStatus': status
        }
        $.messager.confirm('确认!','你确定要'+title+'吗?',function(res){
            if(res){
                $.post("${ctx}/xf/premises/bindMarketingAccount",param,function(response){
                    if (response.result == "1"){
                        $.messager.show({
                            title: '友情提示',
                            msg:'操作成功',
                            timeout:2000,
                            showType:'show',
                            style:{
                                left:'',
                                right:0,
                                top:window.screen.height*0.8,
                                bottom:''
                            }
                        });
                        m_datagrid.datagrid('reload');
                    } else {
                        $.messager.show({
                            title: '友情提示',
                            msg: response.errorMsg,
                            showType:'show',
                            style:{
                                left:'',
                                right:0,
                                top:window.screen.height*0.8,
                                bottom:''
                            }
                        });
                    }
                },'json');
            }
        })
    }



</script>
</head>
<body style="background-color:white;" id="page-body">

<div id="m_toolbar" class="datagrid-toolbar" style="overflow: hidden;height: auto;margin: 15px 0px;background-color: white;border-bottom: none;" border="false">
  <form id="load_list_search" onsubmit="return false;">
  <div class="fm_sty" style="margin: 20px 0px 0px;">
	<div class="ipt_line">
	<span class="ipt_title">楼盘名称</span>
		<input type="text" name="name" class="ipt_226" />
	</div>
	<div class="ipt_line">
		<span class="ipt_title">&emsp;</span>
	</div>
  	<div class="ipt_line">
		<span class="ipt_title">所属商户</span>
		<input name="companyId" class="easyui-combobox" style="height:39px; width:263px;"
			data-options="
				valueField:'id',
				textField:'companyName',
				url:'${ctx}/jr/company/getList?companyType=20&outsideSwitch=1'" />
    </div>
    <div class="ipt_line">
		<span class="ipt_title">楼盘上下架</span>
		<input  name="shelvesStatus" class="easyui-combobox" style="height:39px; width:263px;"
		data-options="
			valueField:'value',
			textField:'text',
			data:[{
				value: -1,
				text:'请选择',
				selected:true
			},{
				value:0,
				text:'未上架'
			},{
				value:1,
				text:'已上架'
			}]"/>
    </div>
	<div class="ipt_line_long">
        <button class="red_100" onclick="searchData()">查询</button>
	</div>    
  </div>
  </form>
</div>

<!-- 查找结果 -->
<table style="margin:0px 20px;" id="m_datagrid">
	<thead>
		<tr>
			<th field="companyName" height="40" >所属商户</th>
			<th field="name" height="40" >楼盘名称</th>
			<th field="manager" width="80" height="40" >项目经理</th>
			<th field="mobile" width="100" height="40" >联系方式</th>
			<th field="marketingNumber" width="100" height="40" >营销号码</th>
			<th data-options="field:'premisesStatus',formatter:function(value,row,index){var key = 'premises_status';return yixun.combobox_formatter(value,row,index,key);}" width="80" height="40" >审核状态</th>
			<th data-options="field:'shelvesStatus', formatter:formatShelvesStatus" width="80" height="40" >上架状态</th>
			<th field="createTime" width="130" height="40" >创建时间</th>
			<th data-options="field:'id',formatter:mShowButton,align:'center'" width="225">操作</th>
		</tr>
	</thead>
</table>

</body>
</html>
